﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Xml;
using BO.Video;
using BO.Infrastructure.StaticData;
using BO.Infrastructure.Utils;

namespace GUI.Services.Video
{
    /// <summary>
    /// Summary description for ListVideoXml
    /// </summary>
    public class ListVideoXml : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            
            var dt = VideoBO.GetNewestVideo(6);
            var objX = new XmlTextWriter(context.Response.OutputStream, null);

            objX.WriteStartDocument();
            objX.WriteStartElement("videolist");

            string str = null;
            foreach (DataRow row in dt.Rows)
            {
                objX.WriteStartElement("video");
                objX.WriteAttributeString("key", row[SqlConstants.Video.KeyVideo] + "&" + row[SqlConstants.Video.PName]);
                objX.WriteAttributeString("thumb", PresentationUtils.Photo.GetVideoAvatarSource(row[SqlConstants.Video.Avatar].ToString()));
                objX.WriteAttributeString("name", row[SqlConstants.Video.Name].ToString().Replace("\"", "'"));
                objX.WriteAttributeString("pname", row[SqlConstants.Video.PName].ToString());

                objX.WriteEndElement();
            }
            objX.WriteEndElement();

            objX.WriteEndDocument();
            objX.Flush();
            objX.Close();
            context.Response.ContentType = "text/xml";
            context.Response.ContentEncoding = Encoding.UTF8;
            context.Response.End();
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}